<?php

/**
 * 会员金钱记录表
 * File Name：MembersMoneyModel.php
 * File Encoding：UTF-8
 * File New Time：2014-5-15 10:27:12
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class MembersMoneyModel extends BaseModel {

    public function tableName() {
        return '{{members_money}}';
    }

    public function rules() {
        return array(
        );
    }

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * 检查用户当前金币是否够
     * @param type $uid 用户UID
     * @param type $money 即将支付的金币
     * @return boolean
     */
    public function balanceAdequate($uid, $money) {
        $userInfo = $this->findByPk($uid);
        if (empty($userInfo)) {
            return false;
        }
        if ($userInfo['money'] >= $money) {
            return true;
        }
        return false;
    }

    public function getUserMoney($uid) {
        $uid = (int) $uid;
        if (!$uid) {
            return false;
        }
        $money = $this->find('uid = :uid', array(':uid' => $uid));
        return $money;
    }

}
